package com.iwomy.envpro.platform.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.envpro.common.core.util.R;
import com.iwomy.envpro.common.log.annotation.SysLog;
import com.iwomy.envpro.platform.dto.AirRealTimeDataDTO;
import com.iwomy.envpro.platform.entity.AirRealTimeDataEntity;
import com.iwomy.envpro.platform.service.AirRealTimeDataService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.iwomy.envpro.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 空气实时数据表
 *
 * @author pig
 * @date 2023-08-31 09:28:08
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/airRealTimeData" )
@Tag(description = "airRealTimeData" , name = "空气实时数据表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class AirRealTimeDataController {

    private final  AirRealTimeDataService airRealTimeDataService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param airRealTimeData 空气实时数据表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('platform_airRealTimeData_view')" )
    public R getAirRealTimeDataPage(@ParameterObject Page page,@ParameterObject AirRealTimeDataEntity airRealTimeData) {
        LambdaQueryWrapper<AirRealTimeDataEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(airRealTimeDataService.page(page, wrapper));
    }


    /**
     * 通过id查询空气实时数据表
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('platform_airRealTimeData_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(airRealTimeDataService.getById(id));
    }

    /**
     * 新增空气实时数据表
     * @param airRealTimeData 空气实时数据表
     * @return R
     */
    @Operation(summary = "新增空气实时数据表" , description = "新增空气实时数据表" )
    @SysLog("新增空气实时数据表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('platform_airRealTimeData_add')" )
    public R save(@RequestBody AirRealTimeDataEntity airRealTimeData) {
        return R.ok(airRealTimeDataService.save(airRealTimeData));
    }

    /**
     * 修改空气实时数据表
     * @param airRealTimeData 空气实时数据表
     * @return R
     */
    @Operation(summary = "修改空气实时数据表" , description = "修改空气实时数据表" )
    @SysLog("修改空气实时数据表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('platform_airRealTimeData_edit')" )
    public R updateById(@RequestBody AirRealTimeDataEntity airRealTimeData) {
        return R.ok(airRealTimeDataService.updateById(airRealTimeData));
    }

    /**
     * 通过id删除空气实时数据表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除空气实时数据表" , description = "通过id删除空气实时数据表" )
    @SysLog("通过id删除空气实时数据表" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('platform_airRealTimeData_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(airRealTimeDataService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param airRealTimeData 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('platform_airRealTimeData_export')" )
    public List<AirRealTimeDataEntity> export(AirRealTimeDataEntity airRealTimeData) {
        return airRealTimeDataService.list(Wrappers.query(airRealTimeData));
    }


	/**
	 * 获取指定所有实时数据
	 * @param page
	 * @param airRealTimeDataDTO
	 * @return
	 */
	@GetMapping("/getAirRealTimeList")
	@PreAuthorize("@pms.hasPermission('platform_airSite_view')" )
	public R getAirRealTimeList(Page page,@ParameterObject AirRealTimeDataDTO airRealTimeDataDTO){
		return  R.ok(airRealTimeDataService.getAirRealTimeList(page,airRealTimeDataDTO));
	}
	/**
	 * 获取指定所有实时数据 不分页
	 * @param airRealTimeDataDTO
	 * @return
	 */
	@GetMapping("/airRealTimeList")
	@PreAuthorize("@pms.hasPermission('platform_airSite_view')" )
	public R airRealTimeList(@ParameterObject AirRealTimeDataDTO airRealTimeDataDTO){
		return  R.ok(airRealTimeDataService.airRealTimeList(airRealTimeDataDTO));
	}

	/**
	 * 获取指定设备的实时数据
	 * @param airRealTimeDataDTO
	 * @return
	 */
	@GetMapping("/airRealTimeByEquipmentId")
	public R airRealTimeByEquipmentId(@ParameterObject AirRealTimeDataDTO airRealTimeDataDTO){
		return  R.ok(airRealTimeDataService.airRealTimeByEquipmentId(airRealTimeDataDTO));
	}


/*********************************APP接口*******************************************/

	/**
	 * 分页查询
	 * @param airRealTimeDataDTO 空气实时数据表
	 * @return
	 */
	@Operation(summary = "分页查询" , description = "分页查询" )
	@GetMapping("/appAirRealTimeDataPage" )
	public R appAirRealTimeDataPage(Page page,@ParameterObject AirRealTimeDataDTO airRealTimeDataDTO) {
		return R.ok(airRealTimeDataService.getAirRealTimeList(page,airRealTimeDataDTO));
	}

	/**
	 * 获取指定设备的实时数据
	 * @param airRealTimeDataDTO
	 * @return
	 */
	@GetMapping("/appAirRealTimeByEquipmentId")
	public R appAirRealTimeByEquipmentId(@ParameterObject AirRealTimeDataDTO airRealTimeDataDTO){
		return R.ok(airRealTimeDataService.airRealTimeByEquipmentId(airRealTimeDataDTO));
	}



}